using Brouteforce.NewManagers;
using Brouteforce.UserInterface.Abstracts;
using Brouteforce.utilities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Brouteforce.UserInterface.UIControls
{
    public class Slider : AbstractUIControl
    {
        private readonly int _minValue;
        private readonly int _maxValue;
        private int _sliderValue;
        public int GetSliderValue { get { return _sliderValue; } }
        private float _sliderXpostion;

        private readonly Texture2D _sliderBackground;
        private readonly Texture2D _sliderScrollBar;
        private readonly Color _valueTextColor ;

        public Slider(Texture2D sliderBackgroundImage, Texture2D sliderScrollBarImage, string name, Rectangle surroundingRectangle, int minVal, int maxVal ,Color ValueColor)
            : base(name, surroundingRectangle)
        {
            _minValue = minVal;
            _maxValue = maxVal;
            _sliderXpostion = 0;
            _sliderBackground = sliderBackgroundImage;
            _sliderScrollBar = sliderScrollBarImage;
            _sliderValue = minVal;
            _sliderXpostion = surroundingRectangle.X;
            _valueTextColor = ValueColor;
        }

        public override void Update()
        {
            if (InputManager.Instance.MouseClicked.IsChangedSince(BFGame.LoopIndex) && InputManager.Instance.IsMouseClickedOn(CurrentUIcontrolRectangle))
            {
                float relativeSliderXpostion = InputManager.Instance.CurMouseX - CurrentUIcontrolRectangle.X;
                relativeSliderXpostion = relativeSliderXpostion / CurrentUIcontrolRectangle.Width;
                _sliderValue = (int)(relativeSliderXpostion * (_maxValue - _minValue));
                _sliderXpostion = InputManager.Instance.CurMouseX;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            BFGame.SpriteBatch.Draw(_sliderBackground, new Rectangle(CurrentUIcontrolRectangle.X, CurrentUIcontrolRectangle.Y, RelativeUIcontrolRectangle.Width, RelativeUIcontrolRectangle.Height), Color.White);
            BFGame.SpriteBatch.Draw(_sliderScrollBar, new Rectangle((int)_sliderXpostion, CurrentUIcontrolRectangle.Y, _sliderScrollBar.Width, _sliderScrollBar.Height), Color.White);
            Draws.DrawString((int)_sliderXpostion, CurrentUIcontrolRectangle.Y, "" + _sliderValue, _valueTextColor);
            //CurrentUIcontrolRectangle.X + CurrentUIcontrolRectangle.Width + 5
        }

        
    }
}
